package com.um.jdy.platform.platform.manager;

import cn.hutool.core.bean.BeanUtil;
import com.um.jdy.common.base.enums.YesOrNo;
import com.um.jdy.common.platform.service.AgreementService;
import com.um.jdy.common.platform.entity.dto.AgreementDTO;
import com.um.jdy.common.platform.entity.po.Agreement;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.manager.BaseManager;
import org.springframework.stereotype.Component;

/**
 * 管理类：隐私政策设置
 */
@Component
public class AgreementManager extends BaseManager<AgreementService> {

    /**
     * 详情
     *
     * @return
     */
    public Response<Agreement> get() {
        Agreement agreement = service.getRow("com_id",getComId());
        if(agreement == null){
            agreement = new Agreement();
            agreement.setIsEnable(YesOrNo.No.name());
            service.save(agreement);
        }
        return Response.success(agreement);
    }

    /**
     * 更新
     *
     * @param id
     * @param dto
     * @return
     */
    public Response update(String id, AgreementDTO dto) {
        Agreement agreement = BeanUtil.copyProperties(dto, Agreement.class);
        agreement.setPlatformAgreementId(id);
        service.updateEntity(agreement);
        return Response.success();
    }

}
